package com.woniuxy.controller;

import com.woniuxy.model.TMenu;
import com.woniuxy.result.Result;
import com.woniuxy.service.TMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("TMenu")
public class TMenuController {

    //注入
    @Autowired
    private TMenuService tMenuService;
    //增加一条数据
    @PostMapping("insert")
    public Result insert(@RequestBody TMenu tMenu){
        tMenuService.add(tMenu);
        return Result.success().msg("添加成功");
    }

    @GetMapping("select")
    public Result getById(@RequestParam Integer id){
        TMenu tMenu = tMenuService.getById(id);
        return Result.success(tMenu).msg("查询成功");
    }

    //修改数据
    @PutMapping("update")
    public Result updateById(@RequestBody TMenu tMenu){
        tMenuService.updateById(tMenu);
        return Result.success().msg("修改成功");
    }

    //删除数据
    @DeleteMapping("delete/{mid}")
    public Result deleteById(@PathVariable Integer mid){
        tMenuService.deleteById(mid);
        return Result.success().msg("删除成功");
    }

    //分页查询数据
    @GetMapping("/page/{page}/{pagesize}")
    public Result pageQuery(@PathVariable Integer page,@PathVariable Integer pagesize, TMenu tMenu){
        List<TMenu> tMenus = tMenuService.page(page,pagesize,tMenu);
        return Result.success(tMenus).msg("分页查询成功");
    }

}
